package com.zzptc.easyshop.facory;

import com.zzptc.easyshop.dao.IDAO;
import com.zzptc.easyshop.util.MyUtil;

import java.util.Map;
//新创建会出现红线，Alt + enter   选第二个  frname Fill
public class DaoFacoryImp implements IFacory {
    //饿汉式
    private static DaoFacoryImp daoFacoryImp = new DaoFacoryImp();

    private DaoFacoryImp() {
    }

    ;

    public static DaoFacoryImp getInstance() {
        return daoFacoryImp;
    }

    @Override
    public IDAO createDAO(String type) throws Exception {

        Map<String, String> map = MyUtil.readXML("dao-config.xml");
        String daostring = map.get(type);
        IDAO dao = (IDAO) Class.forName(daostring).newInstance();

        return dao;
    }

    public static void main(String[] args) {
        try {
            IDAO dao = DaoFacoryImp.getInstance().createDAO("userdao");
            ;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}